﻿using NUnit.Framework;
using System.Collections.Generic;
using OpenSda.Agilcont.Common.Data.Contracts;
using OpenSda.Agilcont.Common.Data.Entities;
using System.Linq;

namespace OpenSda.Agilcont.Common.Data.NhContexts.NuTest
{

    [TestFixture]
    public class EmpresaDataTest : AbstractBaseDataTests
    {
        private IEmpresaData target;
        private IUserData userData;

        // These properties will be injected based on type
        public IEmpresaData EmpresaData { set { target = value; } }
        public IUserData UserData { set { userData = value; } }
        
        [Test()]
        public void GetAllQueryableTest()
        {
            IList<Empresa> empresas = target.GetAllQueryable().Where(e => e.Codigo == "1").ToList();
            Assert.IsTrue(empresas.Count > 0);
        }
        
        [Test]
        public void SaveTest()
        {
            Empresa empresa = this.Save();
            Assert.IsNotNull(empresa.Identity);
        }

        private Empresa Save()
        {
            //User u = userData.GetAll()[0];

            return target.Save(new Empresa()
            {
                Codigo = "747",
                RazonSocial="luz y vida",
                Ruc = "104224266",
               
            });
        }

        [Test()]
        public void GetByIdTest()
        {
            this.GetById(new Empresa() { Codigo = "3"});
        }
        public IList<Empresa> GetById(object Id)
        {
            IList<Empresa> empresas = target.GetAllQueryable().Where(e => e.Codigo == Id.ToString()).ToList();
            return empresas;
        }

        [Test]
        public void GetListByFilterTest()
        {
            this.GetByfilter("");
        }
        public IList<Empresa> GetByfilter(string val)
        {
            IList<Empresa> empresas = target.GetListByFilter(val).ToList();
            return empresas;
        }

        [Test]
        public void EmpresaDaoSeclectTests()
        {
            Empresa e = target.Select(new Empresa() { Codigo = "1" });
            Assert.IsNotNull(e);
        }

        [Test]
        public void EmpresaDaListAllTests()
        {
            var e = target.GetAll();

            Assert.IsNotNull(e);
        }

        [Test]
        public void EmpresaDeleteTests()
        {
            Empresa e = new Empresa();
            e.Codigo = "123";
            target.Delete(e);
        }
    }
}
